home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / omniORB-2.5.0-src.tar.gz / omniORB-2.5.0-src.tar / omniORB_2.5.0 / include / omniORB2 / bufferedStream.h next >
C/C++ Source or Header  |  1998-03-09  |  46KB  |  1,565 lines

  1. // -*- Mode: C++; -*-
  2. //                            Package   : omniORB2
  3. // bufferedstream.h           Created on: 3/3/96
  4. //                            Author    : Sai Lai Lo (sll)
  5. //
  6. //    Copyright (C) 1996, 1997 Olivetti & Oracle Research Laboratory
  7. //
  8. //    This file is part of the omniORB library
  9. //
  10. //    The omniORB library is free software; you can redistribute it and/or
  11. //    modify it under the terms of the GNU Library General Public
  12. //    License as published by the Free Software Foundation; either
  13. //    version 2 of the License, or (at your option) any later version.
  14. //
  15. //    This library is distributed in the hope that it will be useful,
  16. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. //    Library General Public License for more details.
  19. //
  20. //    You should have received a copy of the GNU Library General Public
  21. //    License along with this library; if not, write to the Free
  22. //    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
  23. //    02111-1307, USA
  24. //
  25. //
  26. // Description:
  27. //    *** PROPRIETORY INTERFACE ***
  28. //    
  29.  
  30. /*
  31.   $Log: bufferedStream.h,v $
  32.  * Revision 1.14  1998/03/09  14:33:21  ewc
  33.  * Calls to NP_data() scoped to satisfy aC++ on HPUX
  34.  *
  35.  * Revision 1.13  1998/01/27  16:05:42  ewc
  36.  * Added support necessary for TypeCode and Any
  37.  *
  38.   Revision 1.12  1997/12/23 19:39:43  sll
  39.   For all unbounded sequence templates, the calls to length() are
  40.   made easier for some compiler (HPUX aCC) by specifying the
  41.   base sequence template member function directly.
  42.  
  43.   Revision 1.11  1997/12/09 20:38:59  sll
  44.   Interface extended to provide more hooks to support new transports.
  45.   Sequence array templates now takes an addition argument to indicate the type
  46.   of the array slice.
  47.  
  48.   Revision 1.10  1997/08/21 22:22:29  sll
  49.   New templates for sequence of array.
  50.  
  51.  * Revision 1.9  1997/05/06  16:07:50  sll
  52.  * Public release.
  53.  *
  54.   */
  55.  
  56. #ifndef __BUFFEREDSTREAM_H__
  57. #define __BUFFEREDSTREAM_H__
  58.  
  59. #ifndef Swap16
  60. #define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
  61. #else
  62. #error "Swap16 has already been defined"
  63. #endif
  64.  
  65. #ifndef Swap32
  66. #define Swap32(l) ((((l) & 0xff000000) >> 24) | \
  67.            (((l) & 0x00ff0000) >> 8)  | \
  68.            (((l) & 0x0000ff00) << 8)  | \
  69.            (((l) & 0x000000ff) << 24))
  70. #else
  71. #error "Swap32 has already been defined"
  72. #endif
  73.  
  74. #ifndef MARSHAL
  75. #define MARSHAL(s,type,align,arg) {\
  76.     type *p = (type *) (s).align_and_put_bytes(align,sizeof(type)); \
  77.     *p = arg; \
  78. }
  79. #else
  80. #error "MARSHAL has already been defined"
  81. #endif
  82.  
  83. #ifndef UMARSHAL
  84. #define UMARSHAL(s,type,align,arg) {\
  85.     type *p = (type *) (s).align_and_get_bytes(align,sizeof(type)); \
  86.     arg = *p; \
  87. }
  88. #else
  89. #error "UMARSHAL has already been defined"
  90. #endif
  91.  
  92. class NetBufferedStream : public Strand_Sync {
  93. public:
  94.   NetBufferedStream(Strand *s,
  95.             _CORBA_Boolean RdLock=1,
  96.             _CORBA_Boolean WrLock=1,
  97.             size_t Bufsize=0);
  98.   NetBufferedStream(Rope *r,
  99.             _CORBA_Boolean RdLock=1,
  100.             _CORBA_Boolean WrLock=1,
  101.             size_t Bufsize=0);
  102.   ~NetBufferedStream();
  103.  
  104.  
  105.   friend inline void operator>>= (const _CORBA_Char a,NetBufferedStream &s) {
  106.     MARSHAL(s,_CORBA_Char,omni::ALIGN_1,a);
  107.   }
  108.  
  109.   friend inline void operator<<= (_CORBA_Char &a,NetBufferedStream &s) {
  110.     UMARSHAL(s,_CORBA_Char,omni::ALIGN_1,a);
  111.   }
  112.  
  113.   friend inline void operator>>= (const _CORBA_Short a,NetBufferedStream &s) {
  114.     MARSHAL(s,_CORBA_Short,omni::ALIGN_2,a);
  115.   }
  116.  
  117.   friend inline void operator<<= (_CORBA_Short &a,NetBufferedStream &s) {
  118.     if (s.RdMessageByteOrder() != omni::myByteOrder) {
  119.       _CORBA_Short t;
  120.       UMARSHAL(s,_CORBA_Short,omni::ALIGN_2,t);
  121.       a = Swap16(t);
  122.     }
  123.     else {
  124.       UMARSHAL(s,_CORBA_Short,omni::ALIGN_2,a);
  125.     }
  126.     return;
  127.   }
  128.  
  129.   friend inline void operator>>= (const _CORBA_UShort a,NetBufferedStream &s) {
  130.     MARSHAL(s,_CORBA_UShort,omni::ALIGN_2,a);
  131.   }
  132.  
  133.   friend inline void operator<<= (_CORBA_UShort &a,NetBufferedStream &s) {
  134.     if (s.RdMessageByteOrder() != omni::myByteOrder) {
  135.       _CORBA_UShort t;
  136.       UMARSHAL(s,_CORBA_UShort,omni::ALIGN_2,t);
  137.       a = Swap16(t);
  138.     }
  139.     else {
  140.       UMARSHAL(s,_CORBA_UShort,omni::ALIGN_2,a);
  141.     }
  142.     return;
  143.   }
  144.  
  145.  
  146.   friend inline void operator>>= (const _CORBA_Long a,NetBufferedStream &s) {
  147.     MARSHAL(s,_CORBA_Long,omni::ALIGN_4,a);
  148.   }
  149.  
  150.   friend inline void operator<<= (_CORBA_Long &a,NetBufferedStream &s) {
  151.     if (s.RdMessageByteOrder() != omni::myByteOrder) {
  152.       _CORBA_Long t;
  153.       UMARSHAL(s,_CORBA_Long,omni::ALIGN_4,t);
  154.       a = Swap32(t);
  155.     }
  156.     else {
  157.       UMARSHAL(s,_CORBA_Long,omni::ALIGN_4,a);
  158.     }
  159.     return;
  160.   }
  161.  
  162.   friend inline void operator>>= (const _CORBA_ULong a,NetBufferedStream &s) {
  163.     MARSHAL(s,_CORBA_ULong,omni::ALIGN_4,a);
  164.   }
  165.  
  166.   friend inline void operator<<= (_CORBA_ULong &a,NetBufferedStream &s) {
  167.     if (s.RdMessageByteOrder() != omni::myByteOrder) {
  168.       _CORBA_ULong t;
  169.       UMARSHAL(s,_CORBA_ULong,omni::ALIGN_4,t);
  170.       a = Swap32(t);
  171.     }
  172.     else {
  173.       UMARSHAL(s,_CORBA_ULong,omni::ALIGN_4,a);
  174.     }
  175.     return;
  176.   }
  177.  
  178. #if !defined(NO_FLOAT)
  179.  
  180.   friend inline void operator>>= (const _CORBA_Float a,NetBufferedStream &s) {
  181.     MARSHAL(s,_CORBA_Float,omni::ALIGN_4,a);
  182.   }
  183.  
  184.   friend inline void operator<<= (_CORBA_Float &a,NetBufferedStream &s) {
  185.     if (s.RdMessageByteOrder() != omni::myByteOrder) {
  186.       _CORBA_Float t;
  187.       UMARSHAL(s,_CORBA_Float,omni::ALIGN_4,t);
  188.       _CORBA_ULong tl1 = *((_CORBA_ULong *)&t);
  189.       _CORBA_ULong tl2 = Swap32(tl1);
  190.       a = *((_CORBA_Float *) &tl2);
  191.     }
  192.     else {
  193.       UMARSHAL(s,_CORBA_Float,omni::ALIGN_4,a);
  194.     }
  195.     return;
  196.   }
  197.  
  198.   friend inline void operator>>= (const _CORBA_Double a,NetBufferedStream &s) {
  199.     MARSHAL(s,_CORBA_Double,omni::ALIGN_8,a);
  200.   }
  201.  
  202.   friend inline void operator<<= (_CORBA_Double &a,NetBufferedStream &s) {
  203.     if (s.RdMessageByteOrder() != omni::myByteOrder) {
  204.       _CORBA_Double t;
  205.       UMARSHAL(s,_CORBA_Double,omni::ALIGN_8,t);
  206.       _CORBA_ULong tl1 = ((_CORBA_ULong *)&t)[1];
  207.       _CORBA_ULong tl2 = Swap32(tl1);
  208.       ((_CORBA_ULong *)&a)[0] = tl2;
  209.       tl1 = ((_CORBA_ULong *)&t)[0];
  210.       tl2 = Swap32(tl1);
  211.       ((_CORBA_ULong *)&a)[1] = tl2;
  212.     }
  213.     else {
  214.       UMARSHAL(s,_CORBA_Double,omni::ALIGN_8,a);
  215.     }
  216.     return;
  217.   }
  218.  
  219. #endif
  220.  
  221.   void put_char_array(const _CORBA_Char *b,int size,_CORBA_Boolean startMTU=0,
  222.               _CORBA_Boolean at_most_once=0);
  223.   // marshal in the data in <b>. If startMTU is TRUE(1), the caller indicates
  224.   // that this is the beginning of a new message. If startMTU is
  225.   // TRUE, at_most_once indicates whether this message should be sent
  226.   // with at_most_once semantics.
  227.  
  228.   void get_char_array(_CORBA_Char *b,int size,_CORBA_Boolean startMTU=0);
  229.   // unmarshal data into <b>. If startMTU is TRUE(1), the caller indicates
  230.   // that the beginning of a new message is expected and if the underlying
  231.   // transport thinks otherwise, it is an indication of a protocol violation.
  232.   // In that case, the transport should close the connection.
  233.  
  234.   void skip(_CORBA_ULong size,_CORBA_Boolean startMTU=0);
  235.   // Skip <size> bytes in the incoming buffer. If startMTU is TRUE(1), the
  236.   // caller indicates that after skipping these bytes, the beginning of
  237.   // a new message is expected.
  238.  
  239.   void flush(_CORBA_Boolean endMTU=0);
  240.   // flush the internal transmission buffer. If endMTU is TRUE(1), the
  241.   // caller indicates that the current message has end.
  242.  
  243.   // Byte streams passing through the object can be separated into
  244.   // messages. A message is simply a vector of bytes.  Both the incoming
  245.   // and outgoing stream has an associated message size. The message size
  246.   // is limited to the value of MaxMessageSize().
  247.   //
  248.   // The outgoing message size can be set by the protected member
  249.   // function void WrMessageSize(size_t msgsize). This function can be
  250.   // called at any time to reset the value of the outgoing message size.
  251.   //
  252.   // If the outgoing message size is set to 0, the message is of infinite
  253.   // size. If the outgoing message size is set to N > 0, up to N bytes
  254.   // can be written to the stream. Writing more than N bytes would cause
  255.   // an exception (CORBA::MARSHAL).
  256.   //
  257.   // The public member functions WrMessageAlreadyWritten() and 
  258.   // WrMessageSpaceLeft() return the number of bytes that have already
  259.   // been written and the space left in a message respectively. The functions
  260.   // would return 0 if the outgoing message size is 0.
  261.   //
  262.   // Similarly, the incoming message size can be set by the protected
  263.   // member function void RdMessageSize(size_t msgsize). The
  264.   // public member functions RdMessageAlreadyRead() and RdMessageUnRead()
  265.   // return the number of bytes that have already been read and the
  266.   // remaining bytes to be read respectively.
  267.  
  268.   inline size_t MaxMessageSize() const { return pd_strand->MaxMTU(); }
  269.  
  270.   inline size_t WrMessageSize() const { return pd_wrmsg_size; }
  271.   // Return the current outgoing message size
  272.  
  273.   inline size_t RdMessageSize() const { return pd_rdmsg_size; }
  274.   // Return the current incoming message size
  275.  
  276.   size_t RdMessageAlreadyRead() const;
  277.   // Return the number of bytes that have already been read from the incoming
  278.   // message.
  279.  
  280.   size_t RdMessageUnRead() const;
  281.   // Return the number of bytes in the incoming message that have
  282.   // not been read.
  283.  
  284.   _CORBA_Boolean overrun(_CORBA_ULong len) const {
  285.     if (len <= (_CORBA_ULong) RdMessageUnRead()) return 0;
  286.     else return 1;
  287.   }
  288.  
  289.   inline int RdMessageCurrentAlignment() const {
  290.     return current_inb_alignment();
  291.   }
  292.  
  293.   size_t WrMessageAlreadyWritten() const;
  294.   // Return the number of bytes that have already been written into the
  295.   // outgoing message.
  296.  
  297.   size_t WrMessageSpaceLeft() const;
  298.   // Return the number of bytes in the outgoing message that have not
  299.   // been written.
  300.  
  301.   inline int WrMessageCurrentAlignment() const {
  302.     return current_outb_alignment();
  303.   }
  304.  
  305.   inline _CORBA_Boolean RdMessageByteOrder() const {
  306.     return pd_rdmsg_byte_order;
  307.   }
  308.  
  309. protected:
  310.  
  311.   void RdLock();
  312.   void RdUnlock();
  313.   void WrLock();
  314.   void WrUnlock();
  315.  
  316.   inline _CORBA_Long newRequestID() { return pd_strand->sequenceNumber(); }
  317.  
  318.   void   WrMessageSize(size_t msgsize);
  319.   // For an outgoing message, set the message size.
  320.  
  321.   void   RdMessageSize(size_t msgsize,_CORBA_Boolean byteorder);
  322.   // For an incoming message, set what the message size.
  323.  
  324. private:
  325.   Strand         *pd_strand;
  326.   size_t          pd_ideal_buf_size;
  327.   void           *pd_inb_end;
  328.   void           *pd_outb_end;
  329.   void           *pd_inb_mkr;
  330.   void           *pd_outb_mkr;
  331.   _CORBA_Boolean  pd_RdLock;
  332.   _CORBA_Boolean  pd_WrLock;
  333.  
  334.   size_t          pd_rdmsg_size;
  335.   size_t          pd_wrmsg_size;
  336.   size_t          pd_read;
  337.   size_t          pd_written;
  338.   _CORBA_Boolean  pd_rdmsg_byte_order;
  339.  
  340.   void ensure_rdlocked();
  341.   void ensure_wrlocked();
  342.   void reserve(size_t minimum,_CORBA_Boolean startMTU=0,
  343.            _CORBA_Boolean at_most_once=0);
  344.   void giveback_reserved(_CORBA_Boolean transmit = 0,
  345.              _CORBA_Boolean endMTU=0);
  346.   void receive(size_t minimum,_CORBA_Boolean startMTU=0);
  347.   void giveback_received(_CORBA_Boolean startMTU=0);
  348.   int current_outb_alignment() const;
  349.   int current_inb_alignment() const;
  350.   void rewind_outb_mkr(int oldalignment);
  351.   void rewind_inb_mkr(int oldalignment);
  352.  
  353.   inline void *align_and_put_bytes(omni::alignment_t align,size_t nbytes,
  354.                    _CORBA_Boolean startMTU=0,
  355.                    _CORBA_Boolean at_most_once=0) {
  356.     // If startMTU is TRUE(1), the caller indicates
  357.     // that this is the beginning of a new message. If startMTU is
  358.     // TRUE, at_most_once indicates whether this message should be sent
  359.     // with at_most_once semantics.
  360.     if (startMTU) 
  361.       giveback_reserved(1,1);
  362.     omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_outb_mkr,align);
  363.     omni::ptr_arith_t p2 = p1 + nbytes;
  364.     if ((void *)p2 > pd_outb_end) {
  365.       reserve(p2 - (omni::ptr_arith_t)pd_outb_mkr,startMTU,at_most_once);
  366.       return align_and_put_bytes(align,nbytes);
  367.     }
  368.     pd_outb_mkr = (void *) p2;
  369.     return (void *) p1;
  370.   }
  371.  
  372.   inline void *align_and_get_bytes(omni::alignment_t align,size_t nbytes,
  373.                    _CORBA_Boolean startMTU=0) {
  374.     // If startMTU is TRUE(1), the caller indicates
  375.     // that the beginning of a new message is expected and if the underlying
  376.     // transport thinks otherwise, it is an indication of a protocol violation.
  377.     // In that case, the transport should close the connection.
  378.     if (startMTU)
  379.       giveback_received(1);
  380.     omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_inb_mkr,align);
  381.     omni::ptr_arith_t p2 = p1 + nbytes;
  382.     if ((void *)p2 > pd_inb_end) {
  383.       receive(p2 - (omni::ptr_arith_t)pd_inb_mkr,startMTU);
  384.       return align_and_get_bytes(align,nbytes);
  385.     }
  386.     pd_inb_mkr = (void *) p2;
  387.     return (void *)p1;
  388.   }
  389.  
  390.   NetBufferedStream();
  391.   NetBufferedStream(const NetBufferedStream&);
  392.   NetBufferedStream &operator=(const NetBufferedStream&);
  393. };
  394.  
  395.  
  396.  
  397. class MemBufferedStream {
  398. public:
  399.   MemBufferedStream(size_t initialBufsize=0);
  400.   ~MemBufferedStream();
  401.   
  402.   MemBufferedStream(const MemBufferedStream&, _CORBA_Boolean dupl = 0);
  403.   MemBufferedStream(_CORBA_Char* data);
  404.  
  405.   MemBufferedStream &operator=(const MemBufferedStream&);
  406.  
  407.   void shallowCopy(const MemBufferedStream&);
  408.  
  409.   friend inline void operator>>= (const _CORBA_Char a,MemBufferedStream &s) {
  410.     MARSHAL(s,_CORBA_Char,omni::ALIGN_1,a);
  411.   }
  412.  
  413.   friend inline void operator<<= (_CORBA_Char &a,MemBufferedStream &s) {
  414.     UMARSHAL(s,_CORBA_Char,omni::ALIGN_1,a);
  415.   }
  416.  
  417.   friend inline void operator>>= (const _CORBA_Short a,MemBufferedStream &s) {
  418.     MARSHAL(s,_CORBA_Short,omni::ALIGN_2,a);
  419.   }
  420.  
  421.   friend inline void operator<<= (_CORBA_Short &a,MemBufferedStream &s) {
  422.     if (s.byteOrder() != omni::myByteOrder) {
  423.       _CORBA_Short t;
  424.       UMARSHAL(s,_CORBA_Short,omni::ALIGN_2,t);
  425.       a = Swap16(t);
  426.     }
  427.     else {
  428.       UMARSHAL(s,_CORBA_Short,omni::ALIGN_2,a);
  429.     }
  430.     return;
  431.   }
  432.  
  433.   friend inline void operator>>= (const _CORBA_UShort a,MemBufferedStream &s) {
  434.     MARSHAL(s,_CORBA_UShort,omni::ALIGN_2,a);
  435.   }
  436.  
  437.   friend inline void operator<<= (_CORBA_UShort &a,MemBufferedStream &s) {
  438.     if (s.byteOrder() != omni::myByteOrder) {
  439.       _CORBA_UShort t;
  440.       UMARSHAL(s,_CORBA_UShort,omni::ALIGN_2,t);
  441.       a = Swap16(t);
  442.     }
  443.     else {
  444.       UMARSHAL(s,_CORBA_UShort,omni::ALIGN_2,a);
  445.     }
  446.     return;
  447.   }
  448.  
  449.  
  450.   friend inline void operator>>= (const _CORBA_Long a,MemBufferedStream &s) {
  451.     MARSHAL(s,_CORBA_Long,omni::ALIGN_4,a);
  452.   }
  453.  
  454.   friend inline void operator<<= (_CORBA_Long &a,MemBufferedStream &s) {
  455.     if (s.byteOrder() != omni::myByteOrder) {
  456.       _CORBA_Long t;
  457.       UMARSHAL(s,_CORBA_Long,omni::ALIGN_4,t);
  458.       a = Swap32(t);
  459.     }
  460.     else {
  461.       UMARSHAL(s,_CORBA_Long,omni::ALIGN_4,a);
  462.     }
  463.     return;
  464.   }
  465.  
  466.   friend inline void operator>>= (const _CORBA_ULong a,MemBufferedStream &s) {
  467.     MARSHAL(s,_CORBA_ULong,omni::ALIGN_4,a);
  468.   }
  469.  
  470.   friend inline void operator<<= (_CORBA_ULong &a,MemBufferedStream &s) {
  471.     if (s.byteOrder() != omni::myByteOrder) {
  472.       _CORBA_ULong t;
  473.       UMARSHAL(s,_CORBA_ULong,omni::ALIGN_4,t);
  474.       a = Swap32(t);
  475.     }
  476.     else {
  477.       UMARSHAL(s,_CORBA_ULong,omni::ALIGN_4,a);
  478.     }
  479.     return;
  480.   }
  481.  
  482. #if !defined(NO_FLOAT)
  483.  
  484.   friend inline void operator>>= (const _CORBA_Float a,MemBufferedStream &s) {
  485.     MARSHAL(s,_CORBA_Float,omni::ALIGN_4,a);
  486.   }
  487.  
  488.   friend inline void operator<<= (_CORBA_Float &a,MemBufferedStream &s) {
  489.     if (s.byteOrder() != omni::myByteOrder) {
  490.       _CORBA_Float t;
  491.       UMARSHAL(s,_CORBA_Float,omni::ALIGN_4,t);
  492.       _CORBA_ULong tl1 = *((_CORBA_ULong *)&t);
  493.       _CORBA_ULong tl2 = Swap32(tl1);
  494.       a = *((_CORBA_Float *) &tl2);
  495.     }
  496.     else {
  497.       UMARSHAL(s,_CORBA_Float,omni::ALIGN_4,a);
  498.     }
  499.     return;
  500.   }
  501.  
  502.   friend inline void operator>>= (const _CORBA_Double a,MemBufferedStream &s) {
  503.     MARSHAL(s,_CORBA_Double,omni::ALIGN_8,a);
  504.   }
  505.  
  506.   friend inline void operator<<= (_CORBA_Double &a,MemBufferedStream &s) {
  507.     if (s.byteOrder() != omni::myByteOrder) {
  508.       _CORBA_Double t;
  509.       UMARSHAL(s,_CORBA_Double,omni::ALIGN_8,t);
  510.       _CORBA_ULong tl1 = ((_CORBA_ULong *)&t)[1];
  511.       _CORBA_ULong tl2 = Swap32(tl1);
  512.       ((_CORBA_ULong *)&a)[0] = tl2;
  513.       tl1 = ((_CORBA_ULong *)&t)[0];
  514.       tl2 = Swap32(tl1);
  515.       ((_CORBA_ULong *)&a)[1] = tl2;
  516.     }
  517.     else {
  518.       UMARSHAL(s,_CORBA_Double,omni::ALIGN_8,a);
  519.     }
  520.     return;
  521.   }
  522.  
  523. #endif
  524.  
  525.   void put_char_array(const _CORBA_Char *b,int size);
  526.   void get_char_array(_CORBA_Char *b,int size);
  527.  
  528.  
  529.   void rewind_inout_mkr();
  530.   void rewind_in_mkr();
  531.  
  532.   _CORBA_Boolean byteOrder() const {
  533.     return pd_byte_order;
  534.   }
  535.  
  536.   void byteOrder(_CORBA_Boolean b) {
  537.     pd_byte_order = b;
  538.   }
  539.  
  540.   _CORBA_Boolean RdMessageByteOrder() const {
  541.     return byteOrder();
  542.   }
  543.  
  544.   size_t alreadyRead() const {
  545.     if (pd_in_mkr < pd_out_mkr)
  546.       return ((omni::ptr_arith_t)pd_in_mkr - 
  547.           (omni::ptr_arith_t)startofstream());
  548.     else
  549.       return ((omni::ptr_arith_t)pd_out_mkr - 
  550.           (omni::ptr_arith_t)startofstream());
  551.   }
  552.  
  553.   size_t RdMessageAlreadyRead() const { 
  554.     return alreadyRead(); 
  555.   }
  556.  
  557.   size_t unRead() const {
  558.     if (pd_in_mkr < pd_out_mkr)
  559.       return ((omni::ptr_arith_t)pd_out_mkr - 
  560.           (omni::ptr_arith_t)pd_in_mkr);
  561.     else
  562.       return 0;
  563.   }
  564.  
  565.   size_t RdMessageUnRead() const { 
  566.     return unRead(); 
  567.   }
  568.  
  569.   int rdCurrentAlignment() const {
  570.     int align=((omni::ptr_arith_t)pd_in_mkr & ((int)omni::max_alignment - 1));
  571.     return ((align)? align:(int)omni::max_alignment);
  572.   }
  573.  
  574.   size_t alreadyWritten() const {
  575.     return ((omni::ptr_arith_t)pd_out_mkr - 
  576.         (omni::ptr_arith_t)startofstream());
  577.   }
  578.  
  579.   size_t WrMessageAlreadyWritten() const { 
  580.     return alreadyWritten(); 
  581.   }
  582.  
  583.   int wrCurrentAlignment() const {
  584.     int align=((omni::ptr_arith_t)pd_out_mkr & ((int)omni::max_alignment - 1));
  585.     return ((align)?align:(int)omni::max_alignment);
  586.   }
  587.  
  588.   _CORBA_Boolean overrun(_CORBA_ULong len) const {
  589.     if (pd_noboundcheck || len <= (_CORBA_ULong) unRead()) return 0;
  590.     else return 1;
  591.   }
  592.  
  593.   void reset();
  594.  
  595.   void skip(_CORBA_ULong size,omni::alignment_t align = omni::ALIGN_1);
  596.  
  597.   void *data() const {
  598.     return pd_in_mkr;
  599.   }
  600.  
  601.   void* setSize(size_t sz) {
  602.     if (sz > size()) {
  603.       omni::ptr_arith_t p1 = 
  604.     omni::align_to((omni::ptr_arith_t)pd_out_mkr,omni::ALIGN_1);
  605.       omni::ptr_arith_t p2 = p1 + sz;
  606.       if ((void *)p2 > pd_bufend) {
  607.     grow(p2 - (omni::ptr_arith_t)pd_bufend);
  608.     return align_and_put_bytes(omni::ALIGN_1,sz);
  609.       }
  610.       pd_out_mkr = (void *) p2;
  611.       return (void *) p1;
  612.     }
  613.  
  614.     pd_out_mkr = (void*) ((omni::ptr_arith_t) pd_in_mkr + sz);
  615.     return pd_in_mkr;
  616.   }
  617.         
  618.   size_t size() const;
  619.  
  620. private:
  621.   void     *pd_bufp;
  622.   void     *pd_bufend;
  623.   void     *pd_in_mkr;
  624.   void     *pd_out_mkr;
  625. #define MEMBUFFEREDSTREAM_INLINE_BUF_SIZE 32
  626.   static const int pd_inline_buf_size;
  627.   char      pd_buffer[MEMBUFFEREDSTREAM_INLINE_BUF_SIZE];
  628.   _CORBA_Boolean pd_byte_order;
  629.   _CORBA_Boolean pd_noboundcheck;
  630.   _CORBA_Boolean pd_dupl;
  631.  
  632.  
  633.   inline void *align_and_put_bytes(omni::alignment_t align,size_t nbytes) {
  634.     omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_out_mkr,align);
  635.     omni::ptr_arith_t p2 = p1 + nbytes;
  636.     if ((void *)p2 > pd_bufend) {
  637.       grow(p2 - (omni::ptr_arith_t)pd_out_mkr);
  638.       return align_and_put_bytes(align,nbytes);
  639.     }
  640.     pd_out_mkr = (void *) p2;
  641.     return (void *) p1;
  642.   }
  643.  
  644.   inline void *align_and_get_bytes(omni::alignment_t align,size_t nbytes) {
  645.     omni::ptr_arith_t p1 = omni::align_to((omni::ptr_arith_t)pd_in_mkr,align);
  646.     pd_in_mkr = (void *)(p1 + nbytes);
  647.     if (pd_in_mkr > pd_out_mkr && !pd_noboundcheck) {
  648.       return overrun_error();
  649.     }
  650.     return (void *)p1;
  651.   }
  652.  
  653.   void * startofstream() const;
  654.   void grow(size_t minimum);
  655.   void copy(const MemBufferedStream &);
  656.   void *overrun_error();
  657. };
  658.  
  659. #undef MARSHAL
  660. #undef UMARSHAL
  661.  
  662. template <class T>
  663. inline void
  664. _CORBA_Sequence<T>::operator>>= (NetBufferedStream &s) const
  665. {
  666.   pd_len >>= s;
  667.   for (int i=0; i<(int)pd_len; i++) {
  668.     pd_buf[i] >>= s;
  669.   }
  670.   return;
  671. }
  672.  
  673. template <class T>
  674. inline void
  675. _CORBA_Sequence<T>::operator<<= (NetBufferedStream &s)
  676. {
  677.   _CORBA_ULong l;
  678.   l <<= s;
  679.   if (l > s.RdMessageUnRead()) {
  680.     _CORBA_marshal_error();
  681.     // never reach here
  682.   }
  683.   length(l);
  684.   for (_CORBA_ULong i=0; i<l; i++) {
  685.     pd_buf[i] <<= s;
  686.   }
  687.   return;
  688. }
  689.  
  690. template <class T>
  691. inline void
  692. _CORBA_Sequence<T>::operator>>= (MemBufferedStream &s) const
  693. {
  694.   pd_len >>= s;
  695.   for (int i=0; i<(int)pd_len; i++) {
  696.     pd_buf[i] >>= s;
  697.   }
  698.   return;
  699. }
  700.  
  701. template <class T>
  702. inline void
  703. _CORBA_Sequence<T>::operator<<= (MemBufferedStream &s)
  704. {
  705.   _CORBA_ULong l;
  706.   l <<= s;
  707.   if (s.overrun(l)) {
  708.     _CORBA_marshal_error();
  709.     // never reach here
  710.   }
  711.   length(l);
  712.   for (_CORBA_ULong i=0; i<l; i++) {
  713.     pd_buf[i] <<= s;
  714.   }
  715.   return;
  716. }
  717.  
  718.  
  719. template <class T>
  720. inline
  721. size_t
  722. _CORBA_Unbounded_Sequence<T>::NP_alignedSize(size_t initialoffset) const 
  723. {
  724.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  725.   for (unsigned long i=0; i < _CORBA_Sequence<T>::length(); i++) {
  726.     alignedsize = _CORBA_Sequence<T>::NP_data()[i].NP_alignedSize(alignedsize);
  727.   }
  728.   return alignedsize;
  729. }
  730.  
  731. template <class T>
  732. inline 
  733. void 
  734. _CORBA_Unbounded_Sequence<T>::operator>>= (NetBufferedStream &s) const
  735. {
  736.   _CORBA_Sequence<T>::operator>>=(s);
  737. }
  738.  
  739. template <class T>
  740. inline
  741. void
  742. _CORBA_Unbounded_Sequence<T>::operator<<= (NetBufferedStream &s)
  743. {
  744.   _CORBA_Sequence<T>::operator<<=(s);
  745. }
  746.  
  747. template <class T>
  748. inline
  749. void 
  750. _CORBA_Unbounded_Sequence<T>::operator>>= (MemBufferedStream &s) const
  751. {
  752.   _CORBA_Sequence<T>::operator>>=(s);
  753. }
  754.  
  755. template <class T>
  756. inline
  757. void 
  758. _CORBA_Unbounded_Sequence<T>::operator<<= (MemBufferedStream &s)
  759. {
  760.   _CORBA_Sequence<T>::operator<<=(s);
  761. }
  762.  
  763. template <class T,int max>
  764. inline 
  765. size_t
  766. _CORBA_Bounded_Sequence<T,max>::NP_alignedSize(size_t initialoffset) const 
  767. {
  768.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  769.   for (unsigned long i=0; i < length(); i++) {
  770.     alignedsize = _CORBA_Sequence<T>::NP_data()[i].NP_alignedSize(alignedsize);
  771.   }
  772.   return alignedsize;
  773. }
  774.  
  775. template <class T,int max>
  776. inline 
  777. void
  778. _CORBA_Bounded_Sequence<T,max>::operator>>= (NetBufferedStream &s) const
  779. {
  780.   _CORBA_Sequence<T>::operator>>=(s);
  781. }
  782.  
  783. template <class T,int max>
  784. inline void
  785. _CORBA_Bounded_Sequence<T,max>::operator<<= (NetBufferedStream &s)
  786. {
  787.   _CORBA_ULong l;
  788.   l <<= s;
  789.   if (l > s.RdMessageUnRead() || l > max) {
  790.     _CORBA_marshal_error();
  791.     // never reach here
  792.   }
  793.   
  794.   length(l);
  795.   for (_CORBA_ULong i=0; i<l; i++) {
  796.     _CORBA_Sequence<T>::NP_data()[i] <<= s;
  797.   }
  798.   return;
  799. }
  800.  
  801. template <class T,int max>
  802. inline void
  803. _CORBA_Bounded_Sequence<T,max>::operator>>= (MemBufferedStream &s) const 
  804. {
  805.   _CORBA_Sequence<T>::operator>>=(s);
  806. }
  807.  
  808. template <class T,int max>
  809. inline void
  810. _CORBA_Bounded_Sequence<T,max>::operator<<= (MemBufferedStream &s)
  811. {
  812.   _CORBA_ULong l;
  813.   l <<= s;
  814.   if (s.overrun(l) || l > max) {
  815.     _CORBA_marshal_error();
  816.     // never reach here
  817.   }
  818.   length(l);
  819.   for (_CORBA_ULong i=0; i<l; i++) {
  820.     _CORBA_Sequence<T>::NP_data()[i] <<= s;
  821.   }
  822.   return;
  823. }
  824.  
  825. template <class T,int elmSize,int elmAlignment>
  826. inline
  827. size_t
  828. _CORBA_Unbounded_Sequence_w_FixSizeElement<T,elmSize,elmAlignment>::NP_alignedSize(size_t initialoffset) const 
  829. {
  830.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  831.   if (_CORBA_Sequence<T>::length()) {
  832.     alignedsize = ((alignedsize+(elmAlignment-1)) & ~(elmAlignment-1));
  833.     alignedsize += _CORBA_Sequence<T>::length() * elmSize;
  834.   }
  835.   return alignedsize;
  836. }
  837.  
  838. template <class T,int elmSize,int elmAlignment>
  839. inline
  840. void
  841. _CORBA_Unbounded_Sequence_w_FixSizeElement<T,elmSize,elmAlignment>::operator>>= (NetBufferedStream &s) const
  842. {
  843.   _CORBA_ULong l = _CORBA_Sequence<T>::length();
  844.   l >>= s;
  845.   if (l==0) return;
  846.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  847.     _CORBA_ULong padding = 0;
  848.     if (s.WrMessageCurrentAlignment() != (int)omni::ALIGN_8)
  849.       padding >>= s;
  850.   }
  851.   s.put_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  852. }
  853.  
  854. template <class T,int elmSize,int elmAlignment>
  855. inline
  856. void
  857. _CORBA_Unbounded_Sequence_w_FixSizeElement<T,elmSize,elmAlignment>::operator<<= (NetBufferedStream &s)
  858. {
  859.   _CORBA_ULong l;
  860.   l <<= s;
  861.   if (l*elmSize > s.RdMessageUnRead()) {
  862.     _CORBA_marshal_error();
  863.     // never reach here
  864.   }
  865.   _CORBA_Sequence<T>::length(l);
  866.   if (l==0) return;
  867.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  868.     if (s.RdMessageCurrentAlignment() != (int)omni::ALIGN_8)
  869.       s.skip(sizeof(_CORBA_ULong));
  870.   }
  871.   s.get_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  872.   if (s.RdMessageByteOrder() != omni::myByteOrder && elmAlignment != 1) {
  873.     if (elmSize == 2) {
  874.       for (_CORBA_ULong i=0; i<l; i++) {
  875.     _CORBA_UShort t = ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i];
  876.     ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i] = Swap16(t);
  877.       }
  878.     }
  879.     else if (elmSize == 4) {
  880.       for (_CORBA_ULong i=0; i<l; i++) {
  881.     _CORBA_ULong t = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  882.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = Swap32(t);
  883.       }
  884.     }
  885.     else if (elmSize == 8) {
  886.       l *= 2;
  887.       for (_CORBA_ULong i=0; i<l; i+=2) {
  888.     _CORBA_ULong tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1];
  889.     _CORBA_ULong tl2 = Swap32(tl1);
  890.     tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  891.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = tl2;
  892.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1] = Swap32(tl1);
  893.       }
  894.     }
  895.   }
  896. }
  897.  
  898. template <class T,int elmSize,int elmAlignment>
  899. inline
  900. void
  901. _CORBA_Unbounded_Sequence_w_FixSizeElement<T,elmSize,elmAlignment>::operator>>= (MemBufferedStream &s) const
  902. {
  903.   _CORBA_ULong l = _CORBA_Sequence<T>::length();
  904.   l >>= s;
  905.   if (l==0) return;
  906.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  907.     _CORBA_ULong padding = 0;
  908.     if (s.wrCurrentAlignment() != (int)omni::ALIGN_8)
  909.       padding >>= s;
  910.   }
  911.   s.put_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  912. }
  913.  
  914. template <class T,int elmSize,int elmAlignment>
  915. inline
  916. void
  917. _CORBA_Unbounded_Sequence_w_FixSizeElement<T,elmSize,elmAlignment>::operator<<= (MemBufferedStream &s)
  918. {
  919.   _CORBA_ULong l;
  920.   l <<= s;
  921.   if (s.overrun(l*elmSize)) {
  922.     _CORBA_marshal_error();
  923.     // never reach here
  924.   }
  925.   _CORBA_Sequence<T>::length(l);
  926.   if (l==0) return;
  927.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  928.     if (s.rdCurrentAlignment() != (int)omni::ALIGN_8)
  929.       s.skip(sizeof(_CORBA_ULong));
  930.   }
  931.   s.get_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  932.   if (s.byteOrder() != omni::myByteOrder && elmAlignment != 1) {
  933.     if (elmSize == 2) {
  934.       for (_CORBA_ULong i=0; i<l; i++) {
  935.     _CORBA_UShort t = ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i];
  936.     ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i] = Swap16(t);
  937.       }
  938.     }
  939.     else if (elmSize == 4) {
  940.       for (_CORBA_ULong i=0; i<l; i++) {
  941.     _CORBA_ULong t = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  942.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = Swap32(t);
  943.       }
  944.     }
  945.     else if (elmSize == 8) {
  946.       l *= 2;
  947.       for (_CORBA_ULong i=0; i<l; i+=2) {
  948.     _CORBA_ULong tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1];
  949.     _CORBA_ULong tl2 = Swap32(tl1);
  950.     tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  951.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = tl2;
  952.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1] = Swap32(tl1);
  953.       }
  954.     }
  955.   }
  956. }
  957.  
  958.  
  959.  
  960. template <class T,int max,int elmSize, int elmAlignment>
  961. inline
  962. size_t
  963. _CORBA_Bounded_Sequence_w_FixSizeElement<T,max,elmSize,elmAlignment>::NP_alignedSize(size_t initialoffset) const 
  964. {
  965.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  966.   if (length()) {
  967.     alignedsize = ((alignedsize+(elmAlignment-1)) & ~(elmAlignment-1));
  968.     alignedsize += length() * elmSize;
  969.   }
  970.   return alignedsize;
  971. }
  972.  
  973.  
  974. template <class T,int max,int elmSize, int elmAlignment>
  975. inline
  976. void
  977. _CORBA_Bounded_Sequence_w_FixSizeElement<T,max,elmSize,elmAlignment>::operator>>= (NetBufferedStream &s) const
  978. {
  979.   _CORBA_ULong l = length();
  980.   l >>= s;
  981.   if (l==0) return;
  982.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  983.     _CORBA_ULong padding = 0;
  984.     if (s.WrMessageCurrentAlignment() != (int)omni::ALIGN_8)
  985.       padding >>= s;
  986.   }
  987.   s.put_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  988. }
  989.  
  990. template <class T,int max,int elmSize, int elmAlignment>
  991. inline
  992. void
  993. _CORBA_Bounded_Sequence_w_FixSizeElement<T,max,elmSize,elmAlignment>::operator<<= (NetBufferedStream &s)
  994. {
  995.   _CORBA_ULong l;
  996.   l <<= s;
  997.   if (l*elmSize > s.RdMessageUnRead() || l > max) {
  998.     _CORBA_marshal_error();
  999.     // never reach here
  1000.   }
  1001.   
  1002.   length(l);
  1003.   if (l==0) return;
  1004.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1005.     if (s.RdMessageCurrentAlignment() != (int)omni::ALIGN_8)
  1006.       s.skip(sizeof(_CORBA_ULong));
  1007.   }
  1008.   s.get_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  1009.   if (s.RdMessageByteOrder() != omni::myByteOrder && elmAlignment != 1) {
  1010.     if (elmSize == 2) {
  1011.       for (_CORBA_ULong i=0; i<l; i++) {
  1012.     _CORBA_UShort t = ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i];
  1013.     ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i] = Swap16(t);
  1014.       }
  1015.     }
  1016.     else if (elmSize == 4) {
  1017.       for (_CORBA_ULong i=0; i<l; i++) {
  1018.     _CORBA_ULong t = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  1019.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = Swap32(t);
  1020.       }
  1021.     }
  1022.     else if (elmSize == 8) {
  1023.       l *= 2;
  1024.       for (_CORBA_ULong i=0; i<l; i+=2) {
  1025.     _CORBA_ULong tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1];
  1026.     _CORBA_ULong tl2 = Swap32(tl1);
  1027.     tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  1028.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = tl2;
  1029.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1] = Swap32(tl1);
  1030.       }
  1031.     }
  1032.   }
  1033. }
  1034.  
  1035. template <class T,int max,int elmSize, int elmAlignment>
  1036. inline
  1037. void
  1038. _CORBA_Bounded_Sequence_w_FixSizeElement<T,max,elmSize,elmAlignment>::operator>>= (MemBufferedStream &s) const
  1039. {
  1040.   _CORBA_ULong l = length();
  1041.   l >>= s;
  1042.   if (l==0) return;
  1043.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1044.     _CORBA_ULong padding = 0;
  1045.     if (s.wrCurrentAlignment() != (int)omni::ALIGN_8)
  1046.       padding >>= s;
  1047.   }
  1048.   s.put_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  1049. }
  1050.  
  1051. template <class T,int max,int elmSize, int elmAlignment>
  1052. inline
  1053. void
  1054. _CORBA_Bounded_Sequence_w_FixSizeElement<T,max,elmSize,elmAlignment>::operator<<= (MemBufferedStream &s)
  1055. {
  1056.   _CORBA_ULong l;
  1057.   l <<= s;
  1058.   if (s.overrun(l*elmSize) || l > max) {
  1059.     _CORBA_marshal_error();
  1060.     // never reach here
  1061.   }
  1062.   
  1063.   length(l);
  1064.   if (l==0) return;
  1065.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1066.     if (s.rdCurrentAlignment() != (int)omni::ALIGN_8)
  1067.       s.skip(sizeof(_CORBA_ULong));
  1068.   }
  1069.   s.get_char_array((_CORBA_Char*)_CORBA_Sequence<T>::NP_data(),(int)l*elmSize);
  1070.   if (s.byteOrder() != omni::myByteOrder && elmAlignment != 1) {
  1071.     if (elmSize == 2) {
  1072.       for (_CORBA_ULong i=0; i<l; i++) {
  1073.     _CORBA_UShort t = ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i];
  1074.     ((_CORBA_UShort*)_CORBA_Sequence<T>::NP_data())[i] = Swap16(t);
  1075.       }
  1076.     }
  1077.     else if (elmSize == 4) {
  1078.       for (_CORBA_ULong i=0; i<l; i++) {
  1079.     _CORBA_ULong t = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  1080.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = Swap32(t);
  1081.       }
  1082.     }
  1083.     else if (elmSize == 8) {
  1084.       l *= 2;
  1085.       for (_CORBA_ULong i=0; i<l; i+=2) {
  1086.     _CORBA_ULong tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1];
  1087.     _CORBA_ULong tl2 = Swap32(tl1);
  1088.     tl1 = ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i];
  1089.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i] = tl2;
  1090.     ((_CORBA_ULong*)_CORBA_Sequence<T>::NP_data())[i+1] = Swap32(tl1);
  1091.       }
  1092.     }
  1093.   }
  1094. }
  1095.  
  1096. /////////////////////////////////////////////////////////////////////////////
  1097.  
  1098. template <class T,class T_slice,class Telm,int dimension>
  1099. inline void
  1100. _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator>>= (NetBufferedStream &s) const
  1101. {
  1102.   pd_len >>= s;
  1103.   for (_CORBA_ULong i=0; i<pd_len; i++) {
  1104.     for (_CORBA_ULong j=0; j<dimension; j++) {
  1105.       *((Telm*)(pd_buf[i])+j) >>= s;
  1106.     }
  1107.   }
  1108.   return;
  1109. }
  1110.  
  1111. template <class T,class T_slice,class Telm,int dimension>
  1112. inline void
  1113. _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator<<= (NetBufferedStream &s)
  1114. {
  1115.   _CORBA_ULong l;
  1116.   l <<= s;
  1117.   if (l > s.RdMessageUnRead()) {
  1118.     _CORBA_marshal_error();
  1119.     // never reach here
  1120.   }
  1121.   length(l);
  1122.   for (_CORBA_ULong i=0; i<l; i++) {
  1123.     for (_CORBA_ULong j=0; j<dimension; j++) {
  1124.       *((Telm*)(pd_buf[i])+j) <<= s;
  1125.     }
  1126.   }
  1127.   return;
  1128. }
  1129.  
  1130. template <class T,class T_slice,class Telm,int dimension>
  1131. inline void
  1132. _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator>>= (MemBufferedStream &s) const
  1133. {
  1134.   pd_len >>= s;
  1135.   for (_CORBA_ULong i=0; i<pd_len; i++) {
  1136.     for (_CORBA_ULong j=0; j<dimension; j++) {
  1137.       *((Telm*)(pd_buf[i])+j) >>= s;
  1138.     }
  1139.   }
  1140.   return;
  1141. }
  1142.  
  1143. template <class T,class T_slice,class Telm,int dimension>
  1144. inline void
  1145. _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator<<= (MemBufferedStream &s)
  1146. {
  1147.   _CORBA_ULong l;
  1148.   l <<= s;
  1149.   if (s.overrun(l)) {
  1150.     _CORBA_marshal_error();
  1151.     // never reach here
  1152.   }
  1153.   length(l);
  1154.   for (_CORBA_ULong i=0; i<l; i++) {
  1155.     for (_CORBA_ULong j=0; j<dimension; j++) {
  1156.       *((Telm*)(pd_buf[i])+j) <<= s;
  1157.     }
  1158.   }
  1159.   return;
  1160. }
  1161.  
  1162.  
  1163. template <class T,class T_slice,class Telm,int dimension>
  1164. inline
  1165. size_t
  1166. _CORBA_Unbounded_Sequence_Array<T,T_slice,Telm,dimension>::NP_alignedSize(size_t initialoffset) const 
  1167. {
  1168.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  1169.   for (_CORBA_ULong i=0; 
  1170.        i < _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length(); 
  1171.        i++) {
  1172.     for (_CORBA_ULong j=0; j<dimension; j++) {
  1173.       alignedsize = ((Telm*)(NP_data()[i]) + j)->NP_alignedSize(alignedsize);
  1174.     }
  1175.   }
  1176.   return alignedsize;
  1177. }
  1178.  
  1179. template <class T,class T_slice,class Telm,int dimension>
  1180. inline 
  1181. void 
  1182. _CORBA_Unbounded_Sequence_Array<T,T_slice,Telm,dimension>::operator>>= (NetBufferedStream &s) const
  1183. {
  1184.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator>>=(s);
  1185. }
  1186.  
  1187. template <class T,class T_slice,class Telm,int dimension>
  1188. inline
  1189. void
  1190. _CORBA_Unbounded_Sequence_Array<T,T_slice,Telm,dimension>::operator<<= (NetBufferedStream &s)
  1191. {
  1192.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator<<=(s);
  1193. }
  1194.  
  1195. template <class T,class T_slice,class Telm,int dimension>
  1196. inline
  1197. void 
  1198. _CORBA_Unbounded_Sequence_Array<T,T_slice,Telm,dimension>::operator>>= (MemBufferedStream &s) const
  1199. {
  1200.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator>>=(s);
  1201. }
  1202.  
  1203. template <class T,class T_slice,class Telm,int dimension>
  1204. inline
  1205. void 
  1206. _CORBA_Unbounded_Sequence_Array<T,T_slice,Telm,dimension>::operator<<= (MemBufferedStream &s)
  1207. {
  1208.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator<<=(s);
  1209. }
  1210.  
  1211. template <class T,class T_slice,class Telm,int dimension,int max>
  1212. inline 
  1213. size_t
  1214. _CORBA_Bounded_Sequence_Array<T,T_slice,Telm,dimension,max>::NP_alignedSize(size_t initialoffset) const 
  1215. {
  1216.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  1217.   for (_CORBA_ULong i=0; i < length(); i++) {
  1218.     for (_CORBA_ULong j=0; j < dimension; j++) {
  1219.       alignedsize = ((Telm*)(NP_data()[i])+j)->NP_alignedSize(alignedsize);
  1220.     }
  1221.   }
  1222.   return alignedsize;
  1223. }
  1224.  
  1225. template <class T,class T_slice,class Telm,int dimension,int max>
  1226. inline 
  1227. void
  1228. _CORBA_Bounded_Sequence_Array<T,T_slice,Telm,dimension,max>::operator>>= (NetBufferedStream &s) const
  1229. {
  1230.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator>>=(s);
  1231. }
  1232.  
  1233. template <class T,class T_slice,class Telm,int dimension,int max>
  1234. inline void
  1235. _CORBA_Bounded_Sequence_Array<T,T_slice,Telm,dimension,max>::operator<<= (NetBufferedStream &s)
  1236. {
  1237.   _CORBA_ULong l;
  1238.   l <<= s;
  1239.   if (l > s.RdMessageUnRead() || l > max) {
  1240.     _CORBA_marshal_error();
  1241.     // never reach here
  1242.   }
  1243.   
  1244.   length(l);
  1245.   for (_CORBA_ULong i=0; i<l; i++) {
  1246.     for (_CORBA_ULong j=0; j<dimension; j++) {
  1247.       *((Telm*)(NP_data()[i])+j) <<= s;
  1248.     }
  1249.   }
  1250.   return;
  1251. }
  1252.  
  1253. template <class T,class T_slice,class Telm,int dimension,int max>
  1254. inline void
  1255. _CORBA_Bounded_Sequence_Array<T,T_slice,Telm,dimension,max>::operator>>= (MemBufferedStream &s) const 
  1256. {
  1257.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::operator>>=(s);
  1258. }
  1259.  
  1260. template <class T,class T_slice,class Telm,int dimension,int max>
  1261. inline void
  1262. _CORBA_Bounded_Sequence_Array<T,T_slice,Telm,dimension,max>::operator<<= (MemBufferedStream &s)
  1263. {
  1264.   _CORBA_ULong l;
  1265.   l <<= s;
  1266.   if (s.overrun(l) || l > max) {
  1267.     _CORBA_marshal_error();
  1268.     // never reach here
  1269.   }
  1270.   length(l);
  1271.   for (_CORBA_ULong i=0; i<l; i++) {
  1272.     for (_CORBA_ULong j=0; j<dimension; j++) {
  1273.       *((Telm*)(NP_data()[i])+j) <<= s;
  1274.     }
  1275.   }
  1276.   return;
  1277. }
  1278.  
  1279. template <class T,class T_slice,class Telm,int dimension,int elmSize,int elmAlignment>
  1280. inline
  1281. size_t
  1282. _CORBA_Unbounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,elmSize,elmAlignment>::NP_alignedSize(size_t initialoffset) const 
  1283. {
  1284.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  1285.   if (_CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length()) {
  1286.     alignedsize = ((alignedsize+(elmAlignment-1)) & ~(elmAlignment-1));
  1287.     alignedsize +=_CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length() * 
  1288.                    dimension * elmSize;
  1289.   }
  1290.   return alignedsize;
  1291. }
  1292.  
  1293. template <class T,class T_slice,class Telm,int dimension,int elmSize,int elmAlignment>
  1294. inline
  1295. void
  1296. _CORBA_Unbounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,elmSize,elmAlignment>::operator>>= (NetBufferedStream &s) const
  1297. {
  1298.   _CORBA_ULong l = _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length();
  1299.   l >>= s;
  1300.   if (l==0) return;
  1301.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1302.     _CORBA_ULong padding = 0;
  1303.     if (s.WrMessageCurrentAlignment() != (int)omni::ALIGN_8)
  1304.       padding >>= s;
  1305.   }
  1306.   s.put_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1307. }
  1308.  
  1309. template <class T,class T_slice,class Telm,int dimension,int elmSize,int elmAlignment>
  1310. inline
  1311. void
  1312. _CORBA_Unbounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,elmSize,elmAlignment>::operator<<= (NetBufferedStream &s)
  1313. {
  1314.   _CORBA_ULong l;
  1315.   l <<= s;
  1316.   if (l*dimension*elmSize > s.RdMessageUnRead()) {
  1317.     _CORBA_marshal_error();
  1318.     // never reach here
  1319.   }
  1320.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length(l);
  1321.   if (l==0) return;
  1322.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1323.     if (s.RdMessageCurrentAlignment() != (int)omni::ALIGN_8)
  1324.       s.skip(sizeof(_CORBA_ULong));
  1325.   }
  1326.   s.get_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1327.   if (s.RdMessageByteOrder() != omni::myByteOrder && elmAlignment != 1) {
  1328.     if (elmSize == 2) {
  1329.       l *= dimension;
  1330.       for (_CORBA_ULong i=0; i<l; i++) {
  1331.     _CORBA_UShort t = ((_CORBA_UShort*)NP_data())[i];
  1332.     ((_CORBA_UShort*)NP_data())[i] = Swap16(t);
  1333.       }
  1334.     }
  1335.     else if (elmSize == 4) {
  1336.       l *= dimension;
  1337.       for (_CORBA_ULong i=0; i<l; i++) {
  1338.     _CORBA_ULong t = ((_CORBA_ULong*)NP_data())[i];
  1339.     ((_CORBA_ULong*)NP_data())[i] = Swap32(t);
  1340.       }
  1341.     }
  1342.     else if (elmSize == 8) {
  1343.       l *= 2*dimension;
  1344.       for (_CORBA_ULong i=0; i<l; i+=2) {
  1345.     _CORBA_ULong tl1 = ((_CORBA_ULong*)NP_data())[i+1];
  1346.     _CORBA_ULong tl2 = Swap32(tl1);
  1347.     tl1 = ((_CORBA_ULong*)NP_data())[i];
  1348.     ((_CORBA_ULong*)NP_data())[i] = tl2;
  1349.     ((_CORBA_ULong*)NP_data())[i+1] = Swap32(tl1);
  1350.       }
  1351.     }
  1352.   }
  1353. }
  1354.  
  1355. template <class T,class T_slice,class Telm,int dimension,int elmSize,int elmAlignment>
  1356. inline
  1357. void
  1358. _CORBA_Unbounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,elmSize,elmAlignment>::operator>>= (MemBufferedStream &s) const
  1359. {
  1360.   _CORBA_ULong l = _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length();
  1361.   l >>= s;
  1362.   if (l==0) return;
  1363.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1364.     _CORBA_ULong padding = 0;
  1365.     if (s.wrCurrentAlignment() != (int)omni::ALIGN_8)
  1366.       padding >>= s;
  1367.   }
  1368.   s.put_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1369. }
  1370.  
  1371. template <class T,class T_slice,class Telm,int dimension,int elmSize,int elmAlignment>
  1372. inline
  1373. void
  1374. _CORBA_Unbounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,elmSize,elmAlignment>::operator<<= (MemBufferedStream &s)
  1375. {
  1376.   _CORBA_ULong l;
  1377.   l <<= s;
  1378.   if (s.overrun(l*dimension*elmSize)) {
  1379.     _CORBA_marshal_error();
  1380.     // never reach here
  1381.   }
  1382.   _CORBA_Sequence_Array<T,T_slice,Telm,dimension>::length(l);
  1383.   if (l==0) return;
  1384.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1385.     if (s.rdCurrentAlignment() != (int)omni::ALIGN_8)
  1386.       s.skip(sizeof(_CORBA_ULong));
  1387.   }
  1388.   s.get_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1389.   if (s.byteOrder() != omni::myByteOrder && elmAlignment != 1) {
  1390.     if (elmSize == 2) {
  1391.       l *= dimension;
  1392.       for (_CORBA_ULong i=0; i<l; i++) {
  1393.     _CORBA_UShort t = ((_CORBA_UShort*)NP_data())[i];
  1394.     ((_CORBA_UShort*)NP_data())[i] = Swap16(t);
  1395.       }
  1396.     }
  1397.     else if (elmSize == 4) {
  1398.       l *= dimension;
  1399.       for (_CORBA_ULong i=0; i<l; i++) {
  1400.     _CORBA_ULong t = ((_CORBA_ULong*)NP_data())[i];
  1401.     ((_CORBA_ULong*)NP_data())[i] = Swap32(t);
  1402.       }
  1403.     }
  1404.     else if (elmSize == 8) {
  1405.       l *= 2*dimension;
  1406.       for (_CORBA_ULong i=0; i<l; i+=2) {
  1407.     _CORBA_ULong tl1 = ((_CORBA_ULong*)NP_data())[i+1];
  1408.     _CORBA_ULong tl2 = Swap32(tl1);
  1409.     tl1 = ((_CORBA_ULong*)NP_data())[i];
  1410.     ((_CORBA_ULong*)NP_data())[i] = tl2;
  1411.     ((_CORBA_ULong*)NP_data())[i+1] = Swap32(tl1);
  1412.       }
  1413.     }
  1414.   }
  1415. }
  1416.  
  1417.  
  1418.  
  1419. template <class T,class T_slice,class Telm,int dimension,int max,int elmSize, int elmAlignment>
  1420. inline
  1421. size_t
  1422. _CORBA_Bounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,max,elmSize,elmAlignment>::NP_alignedSize(size_t initialoffset) const 
  1423. {
  1424.   size_t alignedsize = ((initialoffset+3) & ~((int)3))+sizeof(_CORBA_ULong);
  1425.   if (length()) {
  1426.     alignedsize = ((alignedsize+(elmAlignment-1)) & ~(elmAlignment-1));
  1427.     alignedsize += length() * dimension * elmSize;
  1428.   }
  1429.   return alignedsize;
  1430. }
  1431.  
  1432.  
  1433. template <class T,class T_slice,class Telm,int dimension,int max,int elmSize, int elmAlignment>
  1434. inline
  1435. void
  1436. _CORBA_Bounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,max,elmSize,elmAlignment>::operator>>= (NetBufferedStream &s) const
  1437. {
  1438.   _CORBA_ULong l = length();
  1439.   l >>= s;
  1440.   if (l==0) return;
  1441.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1442.     _CORBA_ULong padding = 0;
  1443.     if (s.WrMessageCurrentAlignment() != (int)omni::ALIGN_8)
  1444.       padding >>= s;
  1445.   }
  1446.   s.put_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1447. }
  1448.  
  1449. template <class T,class T_slice,class Telm,int dimension,int max,int elmSize, int elmAlignment>
  1450. inline
  1451. void
  1452. _CORBA_Bounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,max,elmSize,elmAlignment>::operator<<= (NetBufferedStream &s)
  1453. {
  1454.   _CORBA_ULong l;
  1455.   l <<= s;
  1456.   if (l*dimension*elmSize > s.RdMessageUnRead() || l > max) {
  1457.     _CORBA_marshal_error();
  1458.     // never reach here
  1459.   }
  1460.   
  1461.   length(l);
  1462.   if (l==0) return;
  1463.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1464.     if (s.RdMessageCurrentAlignment() != (int)omni::ALIGN_8)
  1465.       s.skip(sizeof(_CORBA_ULong));
  1466.   }
  1467.   s.get_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1468.   if (s.RdMessageByteOrder() != omni::myByteOrder && elmAlignment != 1) {
  1469.     if (elmSize == 2) {
  1470.       l *= dimension;
  1471.       for (_CORBA_ULong i=0; i<l; i++) {
  1472.     _CORBA_UShort t = ((_CORBA_UShort*)NP_data())[i];
  1473.     ((_CORBA_UShort*)NP_data())[i] = Swap16(t);
  1474.       }
  1475.     }
  1476.     else if (elmSize == 4) {
  1477.       l *= dimension;
  1478.       for (_CORBA_ULong i=0; i<l; i++) {
  1479.     _CORBA_ULong t = ((_CORBA_ULong*)NP_data())[i];
  1480.     ((_CORBA_ULong*)NP_data())[i] = Swap32(t);
  1481.       }
  1482.     }
  1483.     else if (elmSize == 8) {
  1484.       l *= 2*dimension;
  1485.       for (_CORBA_ULong i=0; i<l; i+=2) {
  1486.     _CORBA_ULong tl1 = ((_CORBA_ULong*)NP_data())[i+1];
  1487.     _CORBA_ULong tl2 = Swap32(tl1);
  1488.     tl1 = ((_CORBA_ULong*)NP_data())[i];
  1489.     ((_CORBA_ULong*)NP_data())[i] = tl2;
  1490.     ((_CORBA_ULong*)NP_data())[i+1] = Swap32(tl1);
  1491.       }
  1492.     }
  1493.   }
  1494. }
  1495.  
  1496. template <class T,class T_slice,class Telm,int dimension,int max,int elmSize, int elmAlignment>
  1497. inline
  1498. void
  1499. _CORBA_Bounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,max,elmSize,elmAlignment>::operator>>= (MemBufferedStream &s) const
  1500. {
  1501.   _CORBA_ULong l = length();
  1502.   l >>= s;
  1503.   if (l==0) return;
  1504.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1505.     _CORBA_ULong padding = 0;
  1506.     if (s.wrCurrentAlignment() != (int)omni::ALIGN_8)
  1507.       padding >>= s;
  1508.   }
  1509.   s.put_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1510. }
  1511.  
  1512. template <class T,class T_slice,class Telm,int dimension,int max,int elmSize, int elmAlignment>
  1513. inline
  1514. void
  1515. _CORBA_Bounded_Sequence_Array_w_FixSizeElement<T,T_slice,Telm,dimension,max,elmSize,elmAlignment>::operator<<= (MemBufferedStream &s)
  1516. {
  1517.   _CORBA_ULong l;
  1518.   l <<= s;
  1519.   if (s.overrun(l*dimension*elmSize) || l > max) {
  1520.     _CORBA_marshal_error();
  1521.     // never reach here
  1522.   }
  1523.   
  1524.   length(l);
  1525.   if (l==0) return;
  1526.   if ((int)elmAlignment == (int)omni::ALIGN_8) {
  1527.     if (s.rdCurrentAlignment() != (int)omni::ALIGN_8)
  1528.       s.skip(sizeof(_CORBA_ULong));
  1529.   }
  1530.   s.get_char_array((_CORBA_Char*)NP_data(),(int)l*dimension*elmSize);
  1531.   if (s.byteOrder() != omni::myByteOrder && elmAlignment != 1) {
  1532.     if (elmSize == 2) {
  1533.       l *= dimension;
  1534.       for (_CORBA_ULong i=0; i<l; i++) {
  1535.     _CORBA_UShort t = ((_CORBA_UShort*)NP_data())[i];
  1536.     ((_CORBA_UShort*)NP_data())[i] = Swap16(t);
  1537.       }
  1538.     }
  1539.     else if (elmSize == 4) {
  1540.       l *= dimension;
  1541.       for (_CORBA_ULong i=0; i<l; i++) {
  1542.     _CORBA_ULong t = ((_CORBA_ULong*)NP_data())[i];
  1543.     ((_CORBA_ULong*)NP_data())[i] = Swap32(t);
  1544.       }
  1545.     }
  1546.     else if (elmSize == 8) {
  1547.       l *= 2*dimension;
  1548.       for (_CORBA_ULong i=0; i<l; i+=2) {
  1549.     _CORBA_ULong tl1 = ((_CORBA_ULong*)NP_data())[i+1];
  1550.     _CORBA_ULong tl2 = Swap32(tl1);
  1551.     tl1 = ((_CORBA_ULong*)NP_data())[i];
  1552.     ((_CORBA_ULong*)NP_data())[i] = tl2;
  1553.     ((_CORBA_ULong*)NP_data())[i+1] = Swap32(tl1);
  1554.       }
  1555.     }
  1556.   }
  1557. }
  1558.  
  1559. #undef Swap16
  1560. #undef Swap32
  1561.  
  1562. #endif // __BUFFEREDSTREAM_H__
  1563.  
  1564.  
  1565.